<%@page import="com.farm.parameter.FarmParameterService"%>
<%@ page language="java" pageEncoding="utf-8"%>
<%@page import="com.farm.web.constant.FarmConstant"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/view/conf/farmtag.tld" prefix="PF"%>
<div class="container picLUp" style="min-height: 60px;">
	<div
		class="btn-group btn-group-justified  btn-group-lg hidden-lg hidden-md hidden-sm"
		role="group" style="margin-top: 100px;"
		aria-label="Justified button group with nested dropdown">
		<c:if test="${USEROBJ!=null}">
			<!-- 小屏幕展示 -->
			<c:if test="${!learnView.learned }">
				<a
					href="classweb/Pubview.do?classid=${hourview.classview.classt.id}"
					class="btn btn-danger" role="button">开始课程学习</a>
			</c:if>
			<c:if test="${learnView.learned }">
				<c:if test="${hourview.hour.filemodel=='3'}">
					<a href="javascript:openOperatorWin()" class="btn btn-danger"
						role="button">完成本课时学习</a>
				</c:if>
				<c:if test="${hourview.hour.filemodel!='3'}">
					<PF:IfParameterEquals key="config.sys.hour.complete.handable"
						val="true">
						<a href="javascript:openOperatorWin()" class="btn btn-danger"
							role="button">完成本课时学习</a>
					</PF:IfParameterEquals>
				</c:if>
			</c:if>
		</c:if>
	</div>
	<div class="container wpl-class-tab"
		style="padding-left: 0px; padding-right: 0px;">
		<ul class="nav nav-tabs" style="margin-top: 20px;">
			<c:if test="${!empty text }">
				<li role="presentation" class="${!empty text?'active':'' }"><a
					href="#home" aria-controls="home" role="tab" data-toggle="tab"
					style="font-weight: 700;">课时说明 </a></li>
			</c:if>
			<li role="presentation" class="${empty text?'active':'' }"><a
				href="#profile" aria-controls="profile" role="tab" data-toggle="tab"
				style="font-weight: 700;">课时评论 </a></li>
			<li role="presentation"><a href="#hourevaluation"
				aria-controls="hourevaluation" role="tab" data-toggle="tab"
				style="font-weight: 700;">课程评价 </a></li>
			<c:forEach items="${resources}" var="node">
				<!-- 最大化的资源按钮 -->
				<c:set var="isCpage" value="0"></c:set>
				<c:if
					test="${(node.model=='WTS'&&(node.resourcetype=='3'||node.resourcetype=='4'))||(node.model=='WCP'&&(node.resourcetype=='1'||node.resourcetype=='2'))}">
					<!-- 当前页展示 -->
					<li role="presentation" class="hidden-xs"><a
						style="cursor: pointer;"
						onclick="loadTabContent('${node.bindResourceId}',this)"><i
							class="glyphicon ${node.resourceicon}"></i>
							&nbsp;${node.apptypename}${node.resourcename } </a></li>
					<c:set var="isCpage" value="1"></c:set>
				</c:if>
				<c:if test="${isCpage==0}">
					<!-- 新窗口展示 -->
					<li role="presentation" class="hidden-xs"><a target="_blank"
						style="cursor: pointer;"
						onclick="goOutsys('${node.baseurl}${node.resourceurl}')"><i
							class="glyphicon ${node.resourceicon}"></i>
							&nbsp;${node.apptypename}${node.resourcename } </a></li>
				</c:if>
			</c:forEach>
			<c:if test="${!empty resources}">
				<!-- 最小化的资源按钮 -->
				<li role="presentation"
					class="dropdown  hidden-lg hidden-md hidden-sm"><a href="#"
					id="myTabDrop1" class="dropdown-toggle" data-toggle="dropdown"
					aria-controls="myTabDrop1-contents" aria-expanded="false">资源 <span
						class="caret"></span>
				</a>
					<ul class="dropdown-menu" aria-labelledby="myTabDrop1"
						id="myTabDrop1-contents">
						<c:forEach items="${resources}" var="node">
							<li><a target="_blank" class="wlp-tab-drop-a"
								style="cursor: pointer;" onclick="goOutsys('${node.url}')">${node.apptypename}${node.resourcename }
							</a></li>
						</c:forEach>
					</ul></li>
			</c:if>
			<c:if test="${USEROBJ!=null}">
				<li role="presentation"><a target="_blank"
					onclick="hourCollection()" id="WtsHourCollectionButId" data-isc=""
					style="font-weight: 700; cursor: pointer;">课时-取消收藏 </a></li>
			</c:if>
			<li role="presentation"><a href="#hourshare"
				aria-controls="profile" role="tab" data-toggle="tab"
				style="font-weight: 700;"><i class="glyphicon glyphicon-share"></i>&nbsp;分享
			</a></li>
			<li role="presentation" class="hidden-lg hidden-md hidden-sm"><a
				href="<PF:basePath/>classweb/Pubview.do?type=chapter&classid=${hourview.classview.classt.id}"
				style="font-weight: 700; cursor: pointer;">课程目录 </a></li>
		</ul>
	</div>
</div>
<div class="container mainTab" style="padding-bottom: 100px;">
	<div class="row" style="margin-top: 20px;">
		<div class="col-md-9">
			<!-- Tab panes -->
			<div class="tab-content">
				<div role="tabpanel"
					class="tab-pane ${!empty text?'active':'' } ke-content" id="home">
					<PF:InitHtmlContentTag html="${text}" isImgLazy="false"></PF:InitHtmlContentTag>
				</div>
				<div role="tabpanel" class="tab-pane ${empty text?'active':'' }"
					id="profile">
					<!-- 1:专业,2:课程,3:课时 -->
					<jsp:include page="/view/web-simple/commons/commentsBox.jsp">
						<jsp:param name="appid" value="${hourview.hour.id}" />
						<jsp:param name="apptype" value="3" />
					</jsp:include></div>
				<div role="tabpanel" class="tab-pane " id="hourshare">
					<!-- 分享 -->
					<jsp:include page="/view/web-simple/hour/commons/shareUrl.jsp"></jsp:include>
				</div>
				<div role="tabpanel" class="tab-pane " id="hourevaluation">
					<!-- 课程评价 -->
					<!-- 1:专业,2:课程,3:课时 -->
					<jsp:include page="/view/web-simple/commons/evaluationBox.jsp">
						<jsp:param name="appid" value="${hourview.classview.classt.id}" />
						<jsp:param name="apptype" value="2" />
					</jsp:include>
				</div>
				<div role="tabpanel" class="tab-pane " id="loadTabContentId">
					<!-- 通用内容，延迟加载 -->

				</div>
			</div>
		</div>
		<div class="col-md-3 hidden-xs"></div>
	</div>
</div>
<c:if test="${learnView.learned }">
	<!-- 学习中的课程自动弹出学习下一课 -->
	<script type="text/javascript">
		function openOperatorWin() {
			$('#hourOperatorWin').modal('show')
		}
	</script>
</c:if>
<c:if test="${!learnView.learned }">
	<!-- 非学习中的课程无操作 -->
	<script type="text/javascript">
		function openOperatorWin() {

		}
	</script>
</c:if>
<script type="text/javascript">
	function goOutsys(url) {
		if (confirm('该操作将离开当前页面，是否继续?')) {
			window.open(url);
		}
	}

	//在当前页面展示资源内容
	function loadTabContent(bindResourceId, thisObj) {
		$('#loadTabContentId').html('...');
		$('.tab-pane', '.mainTab').removeClass('active');
		$('#loadTabContentId').addClass('active');
		$('#loadTabContentId').load(
				"resourceweb/PubLoad.do?resourceid=" + bindResourceId, {},
				function() {
					$('li', '.wpl-class-tab').removeClass('active');
					$(thisObj).parent('li').addClass('active');
				});
	}

	//取消或者收藏课时
	function hourCollection() {
		var isCollection = $('#WtsHourCollectionButId').attr('data-isc');
		if (isCollection == '1') {
			if (confirm('是否立即取消收藏本课时?')) {
				$.post('socialweb/unfavorite.do', {
					'appid' : '${hourview.hour.id }',
					'apptype' : '3'
				}, function(flag) {
					if (flag.STATE == 0) {
						initCollection('0');
					} else {
						alert(flag.MESSAGE);
					}
				}, 'json');
			}
		} else {
			if (confirm('是否立即收藏本课时?')) {
				$.post('socialweb/favorite.do', {
					'appid' : '${hourview.hour.id }',
					'apptype' : '3'
				}, function(flag) {
					if (flag.STATE == 0) {
						initCollection('1');
					} else {
						alert(flag.MESSAGE);
					}
				}, 'json');
			}
		}
	}
	//初始化课时的收藏状态
	function initCollection(isCollection) {
		if (isCollection == '1') {
			$('#WtsHourCollectionButId').text('课时-取消收藏');
			$('#WtsHourCollectionButId').attr('data-isc', '1');
		} else {
			$('#WtsHourCollectionButId').text('课时-收藏');
			$('#WtsHourCollectionButId').attr('data-isc', '0');
		}
	}
</script>